package com.woniuxy.controller;

import com.woniuxy.entity.ManagerUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;

/**
 * @Author: 马宇航
 * @Todo: TODO
 * @DateTime: 22/02/10/0010 上午 11:00
 * @Component: 成都蜗牛学苑
 **/
@RequestMapping("/UserManager")
@Controller
public class ManagerController {
    @RequestMapping("/addUser")
    public ModelAndView addUser(@Validated @RequestBody ManagerUser manager, BindingResult bindingResult){
        ModelAndView modelAndView = new ModelAndView();
        if (bindingResult.hasErrors()){
            FieldError fieldError = bindingResult.getFieldError();
            modelAndView.addObject("binding",fieldError.getField()+""+bindingResult.getFieldError().getDefaultMessage());
        }
        modelAndView.setViewName("/WEB-INF/jsp/error.jsp");
        return modelAndView;
    }
}
